package com.kun.controller;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.Quarter;
import cn.hutool.core.lang.hash.Hash;
import com.kun.common.Result;
import com.kun.entity.User;
import com.kun.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/eCharts")
public class EChartsController {

    @Autowired
    private UserServiceImpl userService;

    @GetMapping("/queryQuarterUsers")
    public Result queryQuarterUsers(){
        List<User> users = userService.selectAllUsers();

        int q1=0;   //第一季度的user
        int q2=0;   //第二季度的user
        int q3=0;   //第三季度的user
        int q4=0;   //第四季度的user
        for (User user : users) {
            Date create_time = user.getCreate_time();
            DateTime dateTime = new DateTime(create_time);
            Quarter quarter = dateTime.quarterEnum();
            switch (quarter){
                case Q1:q1+=1;break;
                case Q2:q2+=1;break;
                case Q3:q3+=1;break;
                case Q4:q4+=1;break;
                default:break;
            }
        }
        ArrayList<Integer> list = new ArrayList<>();
        list.add(q1);
        list.add(q2);
        list.add(q3);
        list.add(q4);

        return Result.success(list);
    }


}
